def triangles():
    this_res = [1]
    mid = 0
    while True:
        next_res = []
        if len(this_res) % 2 == 0:
            num1 = len(this_res) // 2 + 1
            num2 = len(this_res) // 2
        else:
            num1 = num2 = (len(this_res) + 1) // 2
        # print("{}, num1:{} num2{}", this_res, num1, num2)

        for i in range(0, num1):
            if 0 == i:
                next_res.append(this_res[i])
            else:
                next_res.append(this_res[i] + this_res[i - 1])

        for i in range(num2 - 1, -1, -1):
            if 0 == i:
                next_res.append(this_res[i])
            else:
                next_res.append(this_res[i] + this_res[i - 1])
        yield this_res
        this_res = next_res


g = triangles()
print(next(g))
print(next(g))
print(next(g))
print(next(g))
print(next(g))
